package com.bdqn.util;
import com.aliyun.tea.*;
import com.aliyun.dysmsapi20170525.*;
import com.aliyun.dysmsapi20170525.models.*;
import com.aliyun.teaopenapi.*;
import com.aliyun.teaopenapi.models.*;
import com.aliyun.teautil.*;
import com.aliyun.teautil.models.*;

/**
 * 阿里云发送短信的工具类
 */
public class SMSUtils {
       /**
        * 使用AK&SK初始化账号Client
        * @param accessKeyId
        * @param accessKeySecret
        * @return Client
        * @throws Exception
        */
       public static com.aliyun.dysmsapi20170525.Client createClient(String accessKeyId, String accessKeySecret) throws Exception {
           Config config = new Config()
                   // 您的 AccessKey ID
                   .setAccessKeyId(accessKeyId)
                   // 您的 AccessKey Secret
                   .setAccessKeySecret(accessKeySecret);
           // 访问的域名
           config.endpoint = "dysmsapi.aliyuncs.com";
           return new com.aliyun.dysmsapi20170525.Client(config);
       }

       public static void sendMessage(String accessKeyId,String accessKeySecret,String phone,Integer code) throws Exception {
           com.aliyun.dysmsapi20170525.Client client = SMSUtils.createClient("LTAI5tRvA4RwxVgmLd3eriG9", "dvvrOspLwLJsfqQYnCJsv5x8PImGJ6");
           SendSmsRequest sendSmsRequest = new SendSmsRequest()
                   .setSignName("阿里云短信测试")
                   .setTemplateCode("SMS_154950909")
                   .setPhoneNumbers(phone)
                   .setTemplateParam("{\"code\":\""+code+"\"}");
           RuntimeOptions runtime = new RuntimeOptions();
           try {
               // 复制代码运行请自行打印 API 的返回值
               client.sendSmsWithOptions(sendSmsRequest, runtime);
           } catch (TeaException error) {
               // 如有需要，请打印 error
               com.aliyun.teautil.Common.assertAsString(error.message);
           } catch (Exception _error) {
               TeaException error = new TeaException(_error.getMessage(), _error);
               // 如有需要，请打印 error
               com.aliyun.teautil.Common.assertAsString(error.message);
           }
   }
}
